package com.yycx.module.bus.provider.service.hy.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yycx.bpm.provider.mapper.FlowTaskMapper;
import com.yycx.bpm.provider.model.TaskResponse;
import com.yycx.bpm.provider.service.FlowTaskService;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.utils.SpringContextHolder;
import com.yycx.module.bus.provider.mapper.hy.HyTaskMapper;
import com.yycx.module.bus.provider.service.hy.HyTaskService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 流程表接口实现类
 *
 * @author flyme
 * @date 2020-06-11
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class HyTaskServiceImpl extends BaseServiceImpl<FlowTaskMapper, TaskResponse> implements HyTaskService {

    @Resource
    private HyTaskMapper taskMapper;

    @Override
    public IPage taskPageList(Map params) {
        CriteriaQuery cq = new CriteriaQuery(params);
        PageParams pageParams = cq.getPageParams();
        EntityMap ext = new EntityMap();
        PageInterceptor pageInterceptor = SpringContextHolder.getHandler(cq.getHandlerName(), PageInterceptor.class);
        if (FlymeUtils.isNotEmpty(pageInterceptor)) {
            pageInterceptor.prepare(cq, pageParams, ext);
        }
        Map requestMap = cq.getRequestMap();
        requestMap.putAll(params);
        IPage page = taskMapper.taskPageList(new Page(pageParams.getCurrent(), pageParams.getSize(), pageParams.searchCount()), requestMap);
        List<EntityMap> data = page.getRecords();
        if (FlymeUtils.isNotEmpty(pageInterceptor)) {
            ext.putAll(params);
            pageInterceptor.complete(cq, data, ext);
        }
        page.setRecords(data);
        return page;
    }
}
